home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / Fades ƒ / Rescue Raiders fade.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-11  |  3.1 KB  |  109 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Rescue Raiders fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg timing.h"
  30.  
  31. #define CorrectTime 5
  32. #define theWindowWidth (boundsRect.right-boundsRect.left)
  33. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  34.  
  35. pascal short RescueRaidersFade(Rect boundsRect, Pattern *thePattern);
  36.  
  37. /* One region in 8 parts.  Each part of the region either starts at a corner
  38.    or in the middle of a side and moves progressively clockwise until the
  39.    entire screen is filled. Named after a similar effect in the game Rescue
  40.    Raiders on the Apple ][e (now called Armor Alley™ on the Mac, but it doesn't
  41.    have this effect in it anymore). */
  42.    
  43. pascal short RescueRaidersFade(Rect boundsRect, Pattern *thePattern)
  44. {
  45.     RgnHandle    curregion, boundsRgn, sectrgn;
  46.     int            cx,cy,lastx,lasty;
  47.     int            BlockSize, VBlockSize;
  48.     
  49.     cx = theWindowWidth / 2;
  50.     cy = theWindowHeight / 2;
  51.     BlockSize=theWindowWidth/25;
  52.     VBlockSize=theWindowHeight/25;
  53.  
  54.     lasty=lastx=0;
  55.     boundsRgn=NewRgn();
  56.     SetRectRgn(boundsRgn, boundsRect.left, boundsRect.top, boundsRect.right, boundsRect.bottom);
  57.     sectrgn=NewRgn();
  58.     curregion=NewRgn();
  59.     do
  60.     {
  61.         StartTiming();
  62.  
  63.         SetEmptyRgn(curregion);
  64.         MoveTo(cx,cy);
  65.         OpenRgn();
  66.             LineTo(lastx,0);
  67.             Line(BlockSize,0);
  68.             LineTo(theWindowWidth-lastx-BlockSize,theWindowHeight);
  69.             Line(BlockSize,0);
  70.             LineTo(cx,cy);
  71.             
  72.             LineTo(cx+lastx,0);
  73.             Line(BlockSize,0);
  74.             LineTo(cx-lastx-BlockSize,theWindowHeight);
  75.             Line(BlockSize,0);
  76.             LineTo(cx,cy);
  77.             
  78.             LineTo(theWindowWidth,lasty);
  79.             Line(0,VBlockSize);
  80.             LineTo(0,theWindowHeight-lasty-VBlockSize);
  81.             Line(0,VBlockSize);
  82.             LineTo(cx,cy);
  83.             
  84.             LineTo(theWindowWidth,cy+lasty);
  85.             Line(0,VBlockSize);
  86.             LineTo(0,cy-lasty-VBlockSize);
  87.             Line(0,VBlockSize);
  88.             LineTo(cx,cy);
  89.         CloseRgn(curregion);
  90.         OffsetRgn(curregion, boundsRect.left, boundsRect.top);
  91.         SectRgn(curregion, boundsRgn, sectrgn);
  92.         FillRgn(sectrgn, *thePattern);
  93.  
  94.         lastx+=BlockSize;
  95.         lasty+=VBlockSize;
  96.  
  97.         TimeCorrection(CorrectTime);
  98.     }
  99.     while (lastx<cx);
  100.     
  101.     FillRect(&boundsRect, *thePattern);        /* in case we missed any bits */
  102.     
  103.     DisposeRgn(curregion);
  104.     DisposeRgn(boundsRgn);
  105.     DisposeRgn(sectrgn);
  106.     
  107.     return 0;
  108. }
  109.